//
//  NetWorkTools.swift
//  XDweibo
//
//  Created by HanXingda on 15/6/26.
//  Copyright © 2015年 韩兴达. All rights reserved.
//

import UIKit
import AFNetworking
class NetWorkTools: AFHTTPSessionManager {
    
    //单例
    private static let instance : NetWorkTools = {
       
        let urlString = "https://api.weibo.com/"
        let url = NSURL(string: urlString)
        let tools = NetWorkTools(baseURL: url)!
        tools.responseSerializer.acceptableContentTypes = NSSet(objects: "application/json", "text/json", "text/javascript","text/plain") as! Set<String>
        return tools
        
    }()

    class func sharedNetworkTools() -> NetWorkTools {
        return instance
    }
    
    /**
    URL: https://api.weibo.com/2/statuses/update.json
    参数: access_token
    status
    */

    func postStatusMessage(text: String, finished: (error: NSError?) -> ()) {
        assert(sharedUserAccount != nil, "必须传入acces_token")
        
        let urlString = "2/statuses/update.json"
        let params = ["access_token" : sharedUserAccount!.access_token, "status" : text]
        
        POST(urlString, parameters: params, success: { (_, JSON) -> Void in
            finished(error: nil)
            }) { (_, error) -> Void in
                print(error)
                finished(error: error)
        }
    }
   }
